<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	template="/resources/layout/templateInterno.xhtml"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:t="http://myfaces.apache.org/tomahawk"
    xmlns:rich="http://richfaces.org/rich">
    
    
	<ui:define name="body">
	
		<div class="grid-11-12">
		<h:panelGroup id="exibirTitulo">
			<h:panelGroup rendered="#{funcaoCadastroBean.acaoTela != ''}">
				
					<h1>#{funcaoCadastroBean.acaoTela} FUNÇÃO</h1>
				
			</h:panelGroup>
			<h:panelGroup rendered="#{funcaoCadastroBean.acaoTela == ''}">
				<div class="grid-11-12">
					<h1>PESQUISAR FUNÇÃO</h1>
				</div>
			</h:panelGroup>
		</h:panelGroup>
	</div>
		
		<div class="form">
		<h:form style="width:100%" id="formCadastroFuncao" styleClass="form">
		
		<div  class="field-clear"></div>
		<h:panelGroup id="pgMensagens">
			  <div >
					<h:messages layout="table" errorClass="errorMessage" infoClass="infoMessage" />
			</div>
		</h:panelGroup>
		
		<div  class="field-clear"></div>
		<h:panelGroup rendered="#{funcaoCadastroBean.exibirCadastro}" id="pgDadosPessoais">
			  <t:fieldset id="idfsDadosPessoais" style="width:750px"  legend="Dados">
			  
					<div class="grid-5-12">
						<em class="form-req">*</em>
						<h:outputLabel  id="lbNome" class="form-lbl"  value="Nome:"/>
						<h:inputText maxlength="100"  id="inptNome" styleClass="form-txt" required="true" label="Nome" value="#{funcaoCadastroBean.funcao.noFuncao}" />
					</div>
					<h:panelGroup id="pgIgrejaPertence" >
						<div class="grid-4-12">
							<em class="form-req">*</em>
							<h:outputLabel  id="lbLocalPertencePesquisa"  class="form-lbl"  value="Igreja:"/>
							<h:selectOneMenu converter="indexConverter" required="true" label="Igreja"  id="cbLocalFrequenciaPesquisa"  value="#{funcaoCadastroBean.funcao.igreja}">
							 		<f:selectItem itemLabel="Selecione..." itemValue=""/>
								   <t:selectItems value="#{funcaoCadastroBean.listaIgreja}" var="igreja" itemLabel="#{igreja.nome}" itemValue="#{igreja}"/>
							</h:selectOneMenu>
						</div>
					</h:panelGroup>	
					<div class="field-clear"></div>
					<h:panelGroup rendered="#{funcaoCadastroBean.funcao.coSeqFuncao != null}">
						<div class="grid-2-12">
				  			 <h:outputLabel  id="lbInativar" class="form-lbl"  value="Inativar Regitro?"/>
							 <h:selectBooleanCheckbox  id="checkStCadastro"  styleClass="form-txt" value="#{funcaoCadastroBean.funcao.inativo}" >	
								 <a4j:support id="sptStatus"  ajaxSingle="true" event="onclick"  ></a4j:support>						
							 </h:selectBooleanCheckbox>
						</div>
					</h:panelGroup>
					<div class="field-clear"></div>
					<div class="grid-8-12">
						<h:outputLabel id="lbDescricao" class="form-lbl"  value="Descrição:"/>
						<h:inputTextarea rows="50" cols="150" id="inptDescricao"  styleClass="form-txt" value="#{funcaoCadastroBean.funcao.dsFuncao}" />
					</div> 
			 </t:fieldset>
			<div class="field-clear"></div>
			</h:panelGroup>
			
			 <div  class="field-clear"> </div>
			
			<h:panelGroup id="pgBotaoBotaoVoltar" rendered="#{funcaoCadastroBean.exibirBotaoVoltar}">
				 <div  class="grid-2-12">
						<a4j:commandButton  styleClass="form-button" immediate="true" id="cbVoltar" value="Voltar" reRender="formCadastroFuncao,exibirTitulo" action="#{funcaoCadastroBean.voltar}" >	</a4j:commandButton>
				</div >
			</h:panelGroup>
			
			
			 <h:panelGroup  rendered="#{usuarioLogado.exibirSalvar}">
			 	<h:panelGroup id="pgBotaoSalvar" rendered="#{funcaoCadastroBean.exibirBotaoSalvar}">
					 <div  class="grid-2-12">
							<a4j:commandButton styleClass="form-button" id="cbSalvar" value="Salvar" reRender="formCadastroFuncao,exibirTitulo" action="#{funcaoCadastroBean.salvar}" >	</a4j:commandButton>
					</div >
				</h:panelGroup>
			</h:panelGroup>
			
			<h:panelGroup  rendered="#{usuarioLogado.exibirEditar}">
				<h:panelGroup id="pgBotaoAtualizar" rendered="#{funcaoCadastroBean.exibirBotaoAtualizar}">
					 <div  class="grid-2-12">
							<a4j:commandButton  styleClass="form-button" id="cbAtualizar" value="Atualizar" reRender="formCadastroFuncao,exibirTitulo" action="#{funcaoCadastroBean.salvar}" >	</a4j:commandButton>
					</div >
				</h:panelGroup>
			</h:panelGroup>
			
			
			<h:panelGroup rendered="#{usuarioLogado.exibirExcluir}">
				<h:panelGroup id="pgBotaoBotaoExcluir" rendered="#{funcaoCadastroBean.exibirBotaoExcluir}">
					 <div class="grid-2-12">
							<a4j:commandButton onclick="Richfaces.showModalPanel('modalPanelConfirmaExcluir');" styleClass="form-button" id="cbExcluir" value="Excluir" reRender="formCadastroFuncao" >	</a4j:commandButton>
					</div >
				</h:panelGroup>
			</h:panelGroup>
			<div class="field-clear"></div>
			
			<h:panelGroup   rendered="#{funcaoCadastroBean.exibirPesquisa}" >
				 <t:fieldset id="idfsDadosIgreaj" style="width: 600px; float: left" legend="Filtros">
			 	 <div class="grid-6-12">
						<h:outputLabel class="form-lbl"  value="Nome:"/>				
						<h:inputText styleClass="form-txt" maxlength="100"  value="#{funcaoCadastroBean.funcaoPesquisa.noFuncao}" id="nomePesquisa" />
					 </div>
				</t:fieldset>
				<div class="field-clear"></div>
			 		<div class="grid-2-12">
						<a4j:commandButton id="cbPesquisar" ajaxSingle="true" process="nomePesquisa" reRender="formCadastroFuncao" styleClass="form-button" action="#{funcaoCadastroBean.pesquisar}"   value="Pesquisar" >
						</a4j:commandButton>
					</div>
					<h:panelGroup  rendered="#{usuarioLogado.exibirNovo}">
						<div class="grid-2-12">
							<a4j:commandButton  styleClass="form-button" id="cbNovo" value="Novo" reRender="formCadastroFuncao,exibirTitulo" action="#{funcaoCadastroBean.novo}" >	</a4j:commandButton>
						</div>
					</h:panelGroup>
			 <div class="field-clear"></div>
			
			 <div class="grid-11-12"  >
			  <h:panelGroup id="pgTableResultados">
				 	<rich:dataTable   styleClass="dataTable rich-table rich-table-cell ui-widget-content ui-grid-content" rows="10" 
	                    			 rendered="#{not empty funcaoCadastroBean.listaFuncao}" 
	                    			width="750" border="0" align="center" id="funcaoTable"  var="funcao" value="#{funcaoCadastroBean.listaFuncao}" >
					  <f:facet  name="header">
	                    <rich:columnGroup >
	                            <rich:column style="text-align: center; width:200px"   styleClass="ui-state-default" >
	                                <strong><h:outputText value="Nome" /></strong>
	                            </rich:column>
	                             <rich:column style="text-align: center;"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Descrição" /></strong>
	                            </rich:column>
	                             <rich:column style="text-align: center;"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Status" /></strong>
	                            </rich:column>
	                             <rich:column style="text-align: center;"  styleClass="ui-state-default" >
	                                <strong><h:outputText value="Operações" /></strong>
	                            </rich:column>
	                    	</rich:columnGroup>
	                  </f:facet>
	 				<rich:columnGroup >	
	 					<rich:column  style="text-align: center;" >
							<h:outputText value="#{funcao.noFuncao}" />
						</rich:column>		
						 <rich:column style="text-align: center;" >
							<h:outputText value="#{funcao.dsFuncao}" />
						</rich:column>
						<rich:column  style="text-align: center;">
							<h:outputText value="#{funcao.status}" />
						</rich:column>
						<rich:column style="text-align: center;" >
						<h:panelGroup rendered="#{usuarioLogado.exibirEditar}">
							<a4j:commandLink id="editarFuncao" ajaxSingle="true" value=" " reRender="formCadastroFuncao,exibirTitulo" action="#{funcaoCadastroBean.editar}"  >
								<h:graphicImage value="/resources/imagens/ico_editar.gif" id="gIEdidarFuncao" styleClass="hidelink"/>
								 <f:setPropertyActionListener target="#{funcaoCadastroBean.funcao}" value="#{funcao}"/>  
							</a4j:commandLink>
						</h:panelGroup>
							<h:panelGroup rendered="#{usuarioLogado.exibirExcluir}">
								<a4j:commandLink id="remover" ajaxSingle="true" 
										onclick="Richfaces.showModalPanel('modalPanelConfirmaExcluir');">
									 <h:graphicImage value="/resources/imagens/ico_excluir.gif" id="gIExcluirFuncao" styleClass="hidelink"/>
								   <f:setPropertyActionListener target="#{funcaoCadastroBean.funcao}" value="#{funcao}"/>
								</a4j:commandLink>
							</h:panelGroup>
						</rich:column>
					</rich:columnGroup>
				</rich:dataTable>
				</h:panelGroup>
			</div>
			
			<h:panelGroup id="pgResultadoas">
			<div class="grid-12-12">
				<h:outputText styleClass="infoRegistroNaoEnc" value="#{msg['info.MGS_01']}" rendered="#{funcaoCadastroBean.registroNaoEncontrado}" />
			</div>
			</h:panelGroup>
			 <div class="field-clear"></div>
			<div class="grid-11-12">
				<rich:datascroller align="center" status="" renderIfSinglePage="false" for="funcaoTable" />
			</div>
		
		</h:panelGroup>
		</h:form>
		</div>
		<rich:modalPanel id="modalPanelConfirmaExcluir" width="280"
					autosized="false" resizeable="false" height="110">
			<div class="form">
			<h:form id="fomModal" >
					<center>
						<div style="margin-left: 40px; margin-bottom: 30px" class="grid-9-12" >
							<h:outputText styleClass="infoRegistroNaoEnc" value="#{msg['info.MSG_02']}"  />
						</div>	
						 <div class="field-clear"></div>
						<div style="margin-left: 60px" class="grid-3-12" >
							<a4j:commandButton ajaxSingle="true" value="Confirmar" action="#{funcaoCadastroBean.excluir}" 
								id="btnConfirmar" styleClass="form-button"
								reRender="formCadastroFuncao,exibirTitulo" oncomplete="Richfaces.hideModalPanel('modalPanelConfirmaExcluir');"  style="width=50px">
							</a4j:commandButton>
						</div>	
						<div style="margin-left: 10px" class="grid-3-12" >
							<a4j:commandButton ajaxSingle="true" value="Cancelar" 				id="btnCancelar" styleClass="form-button"
								onclick="Richfaces.hideModalPanel('modalPanelConfirmaExcluir');"  style="width=50px">
							</a4j:commandButton>
						</div>	
					</center>
			</h:form>
		</div>
		
		</rich:modalPanel>
		<t:saveState  value="#{funcaoCadastroBean.exibirCadastro}"/>
	   	<t:saveState  value="#{funcaoCadastroBean.exibirBotaoNovo}"/>	      
	    <t:saveState  value="#{funcaoCadastroBean.exibirBotaoAtualizar}"/>
	    <t:saveState  value="#{funcaoCadastroBean.exibirBotaoExcluir}"/>
	    <t:saveState  value="#{funcaoCadastroBean.exibirBotaoVoltar}"/>
		<t:saveState  value="#{funcaoCadastroBean.exibirBotaoSalvar}"/>
		<t:saveState  value="#{funcaoCadastroBean.exibirPesquisa}"/> 	
		<t:saveState id="funcaoPesquisa" value="#{funcaoCadastroBean.funcaoPesquisa}"/>
		<t:saveState  value="#{funcaoCadastroBean.funcao}"/> 
		<t:saveState value="#{funcaoCadastroBean.listaFuncao}"/>
		 
	</ui:define>
</ui:composition>

